<?php 
namespace Admin\Model;

/**
 * 支付类
 */
class PaymentsModel extends BaseModel {
	/**
	 * 分页列表
	 */
	public function queryByPage() {
		$m = M('payments');
		$sql = "select * from __PREFIX__payments order by payOrder asc";
		$rs = $m->pageQuery($sql);
		// dump($rs);
		foreach ($rs["root"] as $key => $value) {
			 $rs["root"][$key]["paydesc"] = htmlspecialchars_decode($value["paydesc"]) ;
		}
		return $rs;
	}

	/**
	 * 获取指定对象
	 */
	public function get() {
		$m = M('payments');
		$payment = $m->where("id=".(int)I('id'))->find();
		$payConfig = json_decode($payment['payConfig']);
		foreach ($payConfig as $key => $value) {
			$payment[$key] = $value;
		}
		// dump($payment);
		return $payment;
	}

	/**
	  * 修改
	  */
	 public function edit(){
	 	$rd = array('status'=>-1);
	 	$id = (int)I("id",0);
	    
		$m = M('Payments');
		$data["payName"] = I("payName");
		$data["payDesc"] = I("payDesc");
		$data["payOrder"] = (int)I("payOrder");
		$data["payConfig"] = json_encode(I("payConfig")) ;
		$data["enabled"] = 1;
		if($this->checkEmpty($data)){	
			$rs = $m->where("id=".(int)I('id'))->save($data);
			if(false !== $rs){
				$rd['status']= 1;
			}
		}
		return $rd;
	 } 



}

 ?>